package com.xyz.service;
import com.xyz.entity.User;
import com.xyz.mapper.UserMapper;
import com.xyz.util.PasswordUtil;
import com.xyz.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class UserService {
    @Autowired
    private UserMapper userMapper;

    public String register(UserVO userVO) {
        if (!userVO.getPassword().equals(userVO.getConfirmPassword())) {
            return "密码和确认密码不匹配";
        }

        // 密码匹配，进行加密和注册逻辑
        User user = new User();
        user.setUsername(userVO.getUsername());
        user.setPassword(PasswordUtil.encrypt(userVO.getPassword()));
        userMapper.insertUser(user);
        return "注册成功";
    }

    public User login(String username, String password) {
        return userMapper.findByUsernameAndPassword(username, password);
    }

}


